package com.example.sys.splash

import android.content.ComponentName
import android.content.Intent
import android.content.ServiceConnection
import android.os.Bundle
import android.os.Handler
import android.os.IBinder
import android.widget.TextView
import androidx.appcompat.app.AppCompatActivity
import com.alibaba.android.arouter.launcher.ARouter
import com.example.sys.MainAIDL
import com.example.sys.R
import kotlinx.coroutines.*

class SplashActivity : AppCompatActivity(){
    private lateinit var djs : TextView
    var j : Int = 3
    override fun onCreate(savedInstanceState: Bundle?) {
        super.onCreate(savedInstanceState)
        setContentView(R.layout.activity_splash)
        val intent=Intent()
//        intent.action="com.example.sys.MainService"
//        intent.`package`="com.example.sys"
//        bindService(intent,connection, BIND_AUTO_CREATE)
        djs = findViewById(R.id.djs)
        GlobalScope.launch (Dispatchers.IO){
            for (i in 1..4){
                launch(Dispatchers.Main){
                    djs.text = j.toString()+"s"
                    if (j==0){
                        ARouter.getInstance().build("/app/LoginActivity").navigation()
                        finish()
                    }
                }
                delay(1000)
                j--
            }
        }
    }
    private val connection = object  : ServiceConnection{
        override fun onServiceConnected(p0: ComponentName?, p1: IBinder?) {
            var aidl = MainAIDL.Stub.asInterface(p1)
            var name = aidl.name
        }

        override fun onServiceDisconnected(p0: ComponentName?) {
            TODO("Not yet implemented")
        }

    }
}